let arr: number[] = [1, 2, 3]

let arr02: (number | string)[] = [1, '2', 3]

let arr03: any[] = [1, false, '3']

let arr04: Array<number> = [1, 2, 3]

let arr05: Array<number | string> = [1, 2, '3']

let arr06: number[]
arr06 = []
arr06 = [1]
arr06 = [1, 2]
arr06 = [1, 2, 3]

let arr07: number[] = [1, 2, 3]
arr07[3] = 4
arr07.length = 2
console.log(arr07)

let foo = arr07[3]
console.log(foo) // undefined

type Names = string[]
type Name = Names[0] // string
type Name02 = Names[number] // string 特殊写法

const arr08 = [] // never[]
const arr09 = [1] // number[]
const arr10 = ['1'] // string[]

const arr11: number[] = [1, 2, 3]
arr11.push(4)

const arr12: readonly number[] = [1, 2, 3]
// arr12.push(4) // 报错

// TypeScript 将readonly number[]与number[]视为两种不一样的类型，后者是前者的子类型
// 这是因为只读数组没有pop()、push()之类会改变原数组的方法
// 所以number[]的方法数量要多于readonly number[]
// 这意味着number[]其实是readonly number[]的子类型

let arr13: number[] = [1, 2, 3]
let arr14: readonly number[] = [1, 2, 3, 4]

// arr13 = arr14 // 不可以!!!
arr14 = arr13  // 可以√√√

function getSum(arr: number[]) {
  return arr.reduce((acc, curr) => acc + curr)
}

const arr15: readonly number[] = [1, 2, 3]

// getSum(arr15) 报错  父类型赋值给子类型

// readonly与数组的泛型写法一起使用，就会报错。
// const arr16: readonly Array<number> = [1, 2, 3]

// 实际上，TypeScript 提供了两个专门的泛型，用来生成只读数组的类型。
const a1: Readonly<number[]> = [1, 2, 3]
const a2: ReadonlyArray<number> = [1, 2, 3]

const a3 = [1, 2, 3] as const

// a3[0] = 1 报错

const multi: number[][] = [
  [1, 2, 3],
  [4, 5]
]

for (let i = 0; i < multi.length; i++) {
  for (let j = 0; j < multi[i].length; j++) {
    console.log(multi[i][j])
  }
}